package com.hmy.monitor.prometheus.web;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import lombok.Data;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class CustomUrlMonitor {

    /**
     * 统计请求次数
     */
    @Getter
    private Counter requestCount;

    /**
     * 请求处理耗时
     */
    @Getter
    private Timer requestTimer;

    @Autowired
    @Getter
    private MeterRegistry meterRegistry;

    // 其他项目依赖该项目时 配置文件application.yml会被覆盖
    // 需要放在/resources/config目录下才能被正常读取
    @Value("${prometheus.tag.web.test-url.tag}")
    private String requestTag;

    @PostConstruct
    private void init() {
        this.requestCount = meterRegistry.counter("test-url-request-count", "url", "http://127.0.0.1:5004/prometheus/test");
        this.requestTimer = meterRegistry.timer("test-url-request-timer", "url", "http://127.0.0.1:5004/prometheus/test");
    }


}
